package finalproject.model.rooms;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashMap;

import finalproject.model.items.*;
import finalproject.model.player.Player;
import finalproject.view.StringManager;
/**
 * Class Room - a room in an adventure game.
 *
 * This class is part of the "World of Zuul" application. 
 * "World of Zuul" is a very simple, text based adventure game.  
 *
 * A "Room" represents one location in the scenery of the game.  It is 
 * connected to other rooms via exits.  For each existing exit, the room 
 * stores a reference to the neighboring room.
 * 
 * @author  Michael Kölling and David J. Barnes
 * @version 2011.08.10
 */

public abstract class Room implements Interactions<Player>
{
    private String description;
    private boolean isLighted;
    private List<Item> itemList;
    private HashMap<Direction, Room> exits;        // stores exits of this room.

    public HashMap<Direction, Room> getExits() {
        return exits;
    }

    /**
     * Create a room described "description". Initially, it has
     * no exits. "description" is something like "a kitchen" or
     * "an open court yard".
     * @param description The room's description.
     */
    public Room(String description, boolean isLighted) 
    {    	
        this.description = description;
        this.exits = new HashMap<Direction, Room>();
        this.itemList = new ArrayList<Item>();
        this.isLighted = isLighted;
    }

    /**
     * Define an exit from this room.
     * @param direction The direction of the exit.
     * @param neighbor  The room to which the exit leads.
     */
    public void setExit(Direction direction, Room neighbor) 
    {
        exits.put(direction, neighbor);
    }

    /**
     * Add an item to the room
     * @param item The item added to the room
     */
    public void addItem(Item item)
    {
    	itemList.add(item);
    }
    /**
     * @return The short description of the room
     * (the one that was defined in the constructor).
     */
    public String getShortDescription()
    {
        return description;
    }

    /**
     * Return a description of the room in the form:
     *     You are in the kitchen.
     *     Exits: north west
     *     Items: 
     * @return A long description of this room
     */
    public String getLongDescription()
    {
    	String longDescription;
    	longDescription = StringManager.getString("youarein") + description + ".\n" + getExitString();
    	
    	for (Item item : itemList) {
			longDescription += item.toString();
		}
        return longDescription;
    }

    /**
     * Return a string describing the room's exits, for example
     * "Exits: north west".
     * @return Details of the room's exits.
     */
    public String getExitString()
    {
        String returnString = StringManager.getString("exits") + ":";
        Set<Direction> keys = exits.keySet();
        for(Direction exit : keys) {
            returnString += " " + exit;
        }
        return returnString;
    }

    /**
     * Return the room that is reached if we go from this room in direction
     * "direction". If there is no room in that direction, return null.
     * @param direction The exit's direction.
     * @return The room in the given direction.
     */
    public Room getExit(Direction direction) 
    {
        return exits.get(direction);
    }

	/**
	 * @return the itemList
	 */
	public List<Item> getItemList() {
		return itemList;
	}

	/**
	 * @param itemList the itemList to set
	 */
	public void setItemList(List<Item> itemList) {
		this.itemList = itemList;
	}
	
	@Override
	public boolean leavable(Player p)
	{
	    return true;
	}

    public boolean isLighted() {
        return isLighted;
    }
    
    public void switchLightTo(boolean light)
    {
        this.isLighted = light;
    }
	 @Override
	public String toString()
    {
        return description;
    }
	 
	 public String itemList(){
		String stringItemList = "";
		
		for(int i=0;i<itemList.size();i++)
			stringItemList = stringItemList + itemList.get(i) + "\n";		 
		return stringItemList;		 
	 }
	 
}

